package main

import (
	"archive/tar"
	"fmt"
	"os"
)

func main()  {

}

func tarDemo() {
	filetarget := "./tarFile.tar"
	filesource := "./filedata"
	tarfile, err := os.Create(filetarget)
	if err != nil {
		// if file is exist then delete file
		if err == os.ErrExist {
			if err := os.Remove(filetarget); err != nil {
				fmt.Println(err)
			}
		} else {
			fmt.Println(err)
		}
	}
	defer tarfile.Close()
	tarwriter := tar.NewWriter(tarfile)
	sfileInfo, err := os.Stat(filesource)
	if err != nil {
		fmt.Println(err)
	}
	if !sfileInfo.IsDir() {
		tarFile(filesource, sfileInfo, tarwriter)
	} else {
		tarFolder(filesource, tarwriter)
	}
}
